from django.views.generic import UpdateView
from machete.models import Page,Category,Slideshow,Photo,LinkPhotoSlideshow,LinkSlideshowPage
from machete.forms import AdminUpdatePageForm,AdminUpdateCategoryForm,AdminUpdateSlideshowForm,AdminUpdatePhotoForm,\
    AdminUpdateLinkPhotoSlideshowForm, AdminUpdateLinkSlideshowPageForm

class PageUpdateView(UpdateView):

    model = Page
    context_object_name = "page"
    template_name='machete/admin/updatepage.html'
    form_class=AdminUpdatePageForm
    success_url = '/admin/admin_listpage'
    
    def get_context_data(self, **kwargs):
        context = super(PageUpdateView, self).get_context_data(**kwargs)
        pageInView = context['page']
        context['slideshow_list'] = Slideshow.objects.all()
        context['slideshow_linked_list'] = Page.slideshowLinks(pageInView)
        return context
    
class CategoryUpdateView(UpdateView):

    model = Category
    context_object_name = "category"
    template_name='machete/admin/updatecategory.html'
    form_class=AdminUpdateCategoryForm
    success_url = '/admin/admin_listcategory'

    def get_context_data(self, **kwargs):
        context = super(CategoryUpdateView, self).get_context_data(**kwargs)
        return context

class SlideshowUpdateView(UpdateView):

    model = Slideshow
    context_object_name = "slideshow"
    template_name='machete/admin/updateslideshow.html'
    form_class=AdminUpdateSlideshowForm
    success_url = '/admin/admin_listslideshow'

    def get_context_data(self, **kwargs):
        context = super(SlideshowUpdateView, self).get_context_data(**kwargs)
        slideshowInView = context['slideshow']
        context['page_list'] = Page.objects.all()
        context['page_linked_list'] = Slideshow.pageLinks(slideshowInView)
        context['photo_list'] = Photo.objects.all()
        context['photo_linked_list'] = Slideshow.photoLinks(slideshowInView)
        return context
    
class PhotoUpdateView(UpdateView):

    model = Photo
    context_object_name = "photo"
    template_name='machete/admin/updatephoto.html'
    form_class=AdminUpdatePhotoForm
    success_url = '/admin/admin_listphoto'

    def get_context_data(self, **kwargs):
        context = super(PhotoUpdateView, self).get_context_data(**kwargs)
        photoInView = context['photo']
        context['slideshow_list'] = Slideshow.objects.all()
        context['slideshow_linked_list'] = Photo.slideshowLinks(photoInView)
        return context
#   
#class LinkSlideshowPageUpdateView(UpdateView):
#
#    model = LinkSlideshowPage
#    context_object_name = "slideshowpage"
#    template_name='machete/admin/link/updateslideshowpage.html'
#    form_class=AdminUpdateLinkSlideshowPageForm
#    success_url = '/admin/link/admin_listslideshowpage'
#
#    def get_context_data(self, **kwargs):
#        context = super(LinkSlideshowPageUpdateView, self).get_context_data(**kwargs)
#        return context 
#    
#class LinkPhotoSlideshowUpdateView(UpdateView):
#
#    model = LinkPhotoSlideshow
#    context_object_name = "photoslideshow"
#    template_name='machete/admin/link/updatephotoslideshow.html'
#    form_class=AdminUpdateLinkPhotoSlideshowForm
#    success_url = '/admin/admin_listlink_photoslideshow'
#
#    def get_context_data(self, **kwargs):
#        context = super(LinkPhotoSlideshowUpdateView, self).get_context_data(**kwargs)
#        return context
